# -*- coding:utf-8 -*-
# @File       :   login_pgc_user.py
# @Author     :   LINING
# @Time       :   2024/8/2 15:58
# @Description : pgc创作者登录
import random
import time

from Core.elementOpt import Element
from Core.pageOpt import Page


class LoginPgcUser:
    # 用户名输入框
    _user_name = "[name='username']"
    # 密码输入框
    _password = "[name='password']"
    # 登录页点击登录按钮
    _login_button = '.loginButton'
    # 滑块
    _slider = ['locator', '#nc_1_n1z']
    # 立即登录按钮
    _login = '.login_box_btn>span'
    # 登录失败提示框
    _login_fail = '.el-message-box__message>p'
    # 发布视频按钮
    _create_vedio = '.bottonDiv>a>button'


    def __init__(self, page):
        self.page = page
        self.ele = Element(self.page)
        self.page_ = Page(self.page)

    # 点击‘点击登录按钮’
    def click_login_button(self):
        self.ele.element_click(self._login_button)

    # 输入用户名
    def fill_user_name(self, user_name):
        self.ele.element_fill(self._user_name, user_name)

    # 输入密码
    def fill_password(self, password):
        self.ele.element_fill(self._password, password)

    # 滑块验证
    def slider_verify(self):
        # 获取元素坐标
        size = self.ele.element_get_position(self._slider)
        # 鼠标移动到元素
        self.page_.page_mouse_move(size['x']+10, size['y']+5)
        # 按下鼠标左键
        self.page_.page_mouse_down()
        # 鼠标移动
        self.page_.page_mouse_move(size['x']+350, size['y'] + 5)
        # 等接口响应
        time.sleep(1)
        self.page_.page_mouse_up()

    # 点击登录按钮
    def click_login(self):
        self.ele.element_click(self._login)

    # 获取当前页面title
    def get_current_title(self):
        return self.page_.page_get_title()

    # 登录失败提示信息
    def get_fail_message(self):
        return self.ele.element_get_text(self._login_fail)

    # 发布视频按钮
    def find_create_vedio(self):
        return self.ele.element_get_text(self._create_vedio)


